import { createContext, useContext, useState } from "react";

const ProductsContext = createContext(undefined);
const useProductsContext = () => {
  const context = useContext(ProductsContext);
  if (!context)
    throw new Error(
      "ProductContext must be used within a ProductContextProvider"
    );
  return context;
};
const ProductsProvider = (props) => {
  const [isFecthing, setIsFetching] = useState(false);
  const [products, setProducts] = useState([]);
  const [filters, setFilters] = useState([]);

  const ProductContextValue = {
    isFecthing,
    setIsFetching,
    products,
    setProducts,
    filters,
    setFilters,
  };
  return <ProductsContext.Provider value={ProductContextValue} {...props} />;
};

export { ProductsProvider, useProductsContext };
